$ErrorActionPreference = "Stop"

$repoRoot = Join-Path $PSScriptRoot ".." | Resolve-Path | Select-Object -ExpandProperty Path
$imageTag = $env:IMAGE_TAG
if ([string]::IsNullOrEmpty($imageTag)) {
    $imageTag = "rust-os-dev"
}

docker build -t $imageTag -f (Join-Path $repoRoot "Dockerfile") $repoRoot

docker run --rm `
    -v "${repoRoot}:/workspace" `
    -w "/workspace/kernel" `
    $imageTag `
    cargo +nightly bootimage
